package com.sna.snaapplication.mapper;



import com.github.yulichang.base.MPJBaseMapper;
import com.sna.snaapplication.entity.usercore.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends MPJBaseMapper<User> {
    //根据用户名查询用户
    @Select("select * from user where user_name=#{username}")
    User findByUserName(String username);

    @Select("select * from user where user_id=#{userId}")
    User findByUserID(Long Id);


    //号码是否唯一 只返回一条数据
    @Select("SELECT user_id, user_name FROM user WHERE user_name = #{userName} AND del_flag = '0' LIMIT 1")
    User checkUserNameUnique(String userName);

    //更新密码 根据用户id

    @Select("update user set password=#{updatepwd} where user_id=#{toIntExact}")
    void updatePwd(String updatepwd, int toIntExact);

    //添加用户
    @Insert("insert into user(user_name,password,create_time,update_time)" +
            " values (#{username},#{password},now(),now())")
    void add(String username, String password);

    // 更新用户信息
    @Update("update user set nick_name=#{nickName}, phonenumber=#{phonenumber}, email=#{email}, sex=#{sex} where user_id=#{userId}")
    int updateUser(User user);
}

